<?php
	class VillaAction extends BaseAction{
		public function index(){
			if(!$this->isPost()){
				//区域
				$result = M("area")->select();
				$this->assign("area",$result);
				//地铁站
				$ditie  = M("subway")->select();
				$this->assign("ditie",$ditie);
				//租赁方式
				$rent = M("rent")->select();
				$this->assign("rent",$rent);
				//房源类型
				$type = M("type")->select();
				$this->assign("type",$type);
				$this->display();
			}else{
				//获得图片
				$pic = $_FILES['b_img'];
				//获得图的临时路径
				$tmpname = $pic['tmp_name'];
				//获得图片类型
				$type = $pic['type'];
				$type = explode('/',$type);
				$type_1 = $type[0];
				//重新给图片起名
				$picture='xiezilou_'.time().rand(1000,9999).".".$type[1];
				//上传图片时 的报错
				$error=$pic['error'];
				//图片上传的路径
				$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
				if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
					move_uploaded_file($tmpname,$newname);
				}
				
				
				//楼盘名字
				$data['b_name']=$_POST['b_name'];
				//楼盘图片
				$data['b_img'] = $picture;
				//楼盘位置
				$data['b_location']=$_POST['location'];
				//所 属  区
				$data['b_quyu']=$_POST['b_quyu'];
				//所属商圈
				$data['b_district']=$_POST['b_district'];
				//所属地铁线
				$data['b_subway']=$_POST['b_subway'];
				//所属地铁站
				$data['b_subway_station']=$_POST['b_subway_station'];
				//租赁方式
				$data['b_zulin']=$_POST['b_zulin'];
				//房源类型
				$data['b_type']=$_POST['b_type'];
				//房源位置
				$data['b_location']=$_POST['b_location'];
				//开发商
				$data['b_developers']=$_POST['b_developers'];
				//单价
				$data['b_sell']=$_POST['b_sell'];
				//总价
				$data['b_zongjia']=$_POST['b_zongjia'];
				//日租金
				$data['b_d_rent']=$_POST['b_d_rent'];
				//月租金
				$data['b_m_rent']=$_POST['b_m_rent'];
				//建筑面积
				$data['b_build_area']=$_POST['b_build_area'];
				//使用面积
				$data['b_use_area']=$_POST['b_use_area'];
				//详细标题
				$data['b_title']=$_POST['b_title'];
				//所在楼层
				$data['b_floor']=$_POST['b_floor'];
				//装修状况
				$data['b_decoration']=$_POST['b_decoration'];
				//楼盘等级
				$data['b_rating']=$_POST['b_rating'];
				//支付方式
				$data['b_pay_type']=$_POST['b_pay_type'];
				//配套设施
				$data['b_supproting']=$_POST['b_supproting'];
				//房源描述
				$data['b_description_info']=$_POST['b_description_info'];
				//图片描述
				$data['b_description_img']=$_POST['b_description_img'];
				//地图交通
				$data['b_description_map']=$_POST['b_description_map'];
				//楼盘简介
				$data['b_summary_info']=$_POST['b_summary_info'];
				//周边设施
				$data['b_nearby']=$_POST['b_nearby'];
				
				$result = M("bieshu")->data($data)->add();
				if($result){
					$this->assign("jumpUrl","__URL__/lists");
					$this->assign("waitSecond",3);
					$this->success("写字楼添加成功！！！");
				}else{
					echo M("bieshu")->getlastsql();
				}


				//$data['']=$_POST[''];
			}
		}

		public function lists(){
			if(!$this->isPost()){
				$xiezilou = M("bieshu")->select();
				$this->assign("result",$xiezilou);
				$this->display();
			}else{
				if($_POST['fun']=="del"){
					$b_id = $_POST['b_id'];
					$result = M("bieshu")->where("b_id=$b_id")->delete();
					if($result){
						echo "1"; 
					}else{
						echo "0";
					}
				}
				if($_POST['fun']=='updates'){
					$b_id = $_POST['b_id'];
					$result = M("bieshu")->where("b_id=$b_id")->select();

					$this->assign("result",$result);	
				
					//区域
					$result = M("area")->select();
					$this->assign("area",$result);
					//地铁站
					$ditie  = M("subway")->select();
					$this->assign("ditie",$ditie);
					//租赁方式
					$rent = M("rent")->select();
					$this->assign("rent",$rent);
					//房源类型
					$type = M("type")->select();
					$this->assign("type",$type);

					$this->display("updates");
				}
				if($_POST['fun']=='u'){
					$b_id = $_POST['b_id'];
				//获得图片
				$pic = $_FILES['b_img'];
				//获得图的临时路径
				$tmpname = $pic['tmp_name'];
				//获得图片类型
				$type = $pic['type'];
				$type = explode('/',$type);
				$type_1 = $type[0];
				//重新给图片起名
				$picture='xiezilou_'.time().rand(1000,9999).".".$type[1];
				//上传图片时 的报错
				$error=$pic['error'];
				//图片上传的路径
				$newname=ROOT_DIR.DS.'Public/Upload/'.$picture;
				if(is_uploaded_file($tmpname) && $type_1 == 'image' && $error == '0'){
					move_uploaded_file($tmpname,$newname);
				}
				
				
				//楼盘名字
				$data['b_name']=$_POST['b_name'];
				//楼盘图片
				$data['b_img'] = $picture;
				//楼盘位置
				$data['b_location']=$_POST['location'];
				//所 属  区
				$data['b_quyu']=$_POST['b_quyu'];
				//所属商圈
				$data['b_district']=$_POST['b_district'];
				//所属地铁线
				$data['b_subway']=$_POST['b_subway'];
				//所属地铁站
				$data['b_subway_station']=$_POST['b_subway_station'];
				//租赁方式
				$data['b_zulin']=$_POST['b_zulin'];
				//房源类型
				$data['b_type']=$_POST['b_type'];
				//房源位置
				$data['b_location']=$_POST['b_location'];
				//开发商
				$data['b_developers']=$_POST['b_developers'];
				//单价
				$data['b_sell']=$_POST['b_sell'];
				//总价
				$data['b_zongjia']=$_POST['b_zongjia'];
				//日租金
				$data['b_d_rent']=$_POST['b_d_rent'];
				//月租金
				$data['b_m_rent']=$_POST['b_m_rent'];
				//建筑面积
				$data['b_build_area']=$_POST['b_build_area'];
				//使用面积
				$data['b_use_area']=$_POST['b_use_area'];
				//详细标题
				$data['b_title']=$_POST['b_title'];
				//所在楼层
				$data['b_floor']=$_POST['b_floor'];
				//装修状况
				$data['b_decoration']=$_POST['b_decoration'];
				//楼盘等级
				$data['b_rating']=$_POST['b_rating'];
				//支付方式
				$data['b_pay_type']=$_POST['b_pay_type'];
				//配套设施
				$data['b_supproting']=$_POST['b_supproting'];
				//房源描述
				$data['b_description_info']=$_POST['b_description_info'];
				//图片描述
				$data['b_description_img']=$_POST['b_description_img'];
				//地图交通
				$data['b_description_map']=$_POST['b_description_map'];
				//楼盘简介
				$data['b_summary_info']=$_POST['b_summary_info'];
				//周边设施
				$data['b_nearby']=$_POST['b_nearby'];
				$result = M("bieshu")->data($data)->where("b_id=$b_id")->save();
				if($result){
					$this->assign("jumpUrl","__URL__/lists");
					$this->assign("waitSecond",3);
					$this->success("修改成功！！！");
				}else{
					$this->assign("jumpUrl","__URL__/lists");
					$this->assign("waitSecond",3);
					$this->error("修改失败！！！");		
				
				}
				}
			}
		
		}
		

	}



?>